#ifndef _IUPACKETIP_HPP_
#define _IUPACKETIP_HPP_

#include "iuPacket.hpp"
#include <list>
#include "iuIPAddress.hpp"
#include <list>

/**
 * @brief Classe representant un datagramme IP
 */
class iuPacketIP : public iuPacket
{
public:
   iuPacketIP();
   ~iuPacketIP();
   
   uint16_t getBufferLen() const; 
   uint16_t fromBuffer(const char *buffer, uint16_t len);
   uint16_t toBuffer(char *buffer) const;

   std::list<iuPacketIP *> fragment(uint16_t mtu);
   void                    merge(const std::list<iuPacketIP *> &fragments);  
   bool                    isFragment();

   void               setDestination(const iuIPAddress &dest);
   const iuIPAddress &getDestination() const;
   void               setSource(const iuIPAddress &src);
   const iuIPAddress &getSource() const;
   void               setId(uint16_t id);
   uint16_t           getId() const;
   void               setFlags(bool dontFragment, bool moreFragment);
   void               getFlags(bool *dontFragment, bool *moreFragment) const;
   void               setOffset(uint16_t offset);
   uint16_t           getOffset() const;
   void               setTTL(uint8_t ttl);
   uint8_t            getTTL() const;
   void               setProtocol(uint8_t protocol);
   uint8_t            getProtocol() const;
   void               setData(iuPacket *data);
   iuPacket          *getData() const;
   
   static uint16_t getNextId();

private:
   uint16_t m_id;
   uint16_t m_offset;
   bool m_dontFragment;
   bool m_moreFragment;
   uint8_t m_ttl;
   uint8_t m_protocol;
   iuIPAddress m_src;
   iuIPAddress m_dest;
   iuPacket *m_data;

   static uint16_t m_nextId;
};

#endif
